package com.example.friendfindertwo.data.helper;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class EventTable {
	// table name
	public static final String TABLE_EVENT ="event";
	//primary key
	public static final String COLUMN_ID = "_id";
	//columns
	public static final String COLUMN_CREATION_DATE = "creation_date";
	public static final String COLUMN_END_DATE = "end_date";
	public static final String COLUMN_START_DATE = "start_date";
	public static final String COLUMN_TITLE = "title";
	public static final String COLUMN_DESCRIPTION = "description";
	public static final String COLUMN_PLACE_NAME = "place_name";
	public static final String COLUMN_POSITION_LONGITUDE = "position_longitude";
	public static final String COLUMN_POSITION_LATITUDE = "position_latitude";
	// foreign keys
	public static final String COLUMN_CATEGORY = "category";
	public static final String COLUMN_CREATOR = "creator";

private static final String TABLE_CREATE = "create table " + TABLE_EVENT
	+ " ( " + COLUMN_ID + " integer primary key autoincrement, "
	+ COLUMN_TITLE + " text not null, "
	+ COLUMN_CREATION_DATE + " integer not null, "
	+ COLUMN_END_DATE + " integer not null, "
	+ COLUMN_START_DATE + " integer not null, "
	+ COLUMN_DESCRIPTION + " text, "
	+ COLUMN_PLACE_NAME + " text, "
	+ COLUMN_POSITION_LONGITUDE + " integer not null, "
	+ COLUMN_POSITION_LATITUDE + " integer not null, "
	+ COLUMN_CATEGORY + " integer not null, "
	+ COLUMN_CREATOR + " integer not null, "
	+ " FOREIGN KEY ("+COLUMN_CATEGORY+") REFERENCES "+CategoryTable.TABLE_CATEGORY+" ("+CategoryTable.COLUMN_ID+")"
	+ " FOREIGN KEY ("+COLUMN_CREATOR+") REFERENCES "+FriendTable.TABLE_FRIEND+" ("+FriendTable.COLUMN_ID+"));";


	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(TABLE_CREATE);
	}
	
	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		Log.w(EventTable.class.getName(), " Original version: " + oldVersion
				+ " new version" + newVersion);
		database.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENT);
		onCreate(database);
	} 

}
